<template>
	<view class="container">
		<view class="tui-cells">
			<textarea class="tui-textarea" name="desc" placeholder="发表你的猜想..." maxlength="500" placeholder-class="tui-phcolor-color"
			 auto-focus v-model="desc"/>
			<view class="tui-textarea-counter">0/500</view>
  </view>
 <!-- <view class="tui-enclosure">
    <tui-icon name="satisfied" size="25" class="tui-mr"></tui-icon>
    <tui-icon name="picture" size="25" class="tui-mr"></tui-icon>
    <tui-icon name="link" size="22" class="tui-mr"></tui-icon>
  </view> -->
  <view class="tui-cmt-btn">
    <tui-button @tap="updata">发表</tui-button>
  </view>
</view>
</template>

<script>
	import tuiIcon from "@/components/icon/icon"
	import tuiButton from "@/components/button/button"
	export default {
		components: {
			tuiIcon,
			tuiButton
		},
		data() {
			return {
				detail:{},
				desc:''
			}
		},
		methods: {
			updata(){
				if (!this.desc) {
					uni.showToast({ title: '请输入评论内容', icon: 'none' });
					return;
				}
				let user = uni.getStorageSync('userInfo');
				if(user.is_weixin==0){
					uni.showToast({ title: '请授权微信登录参与评论', icon: 'none',duration:2000 });
					setTimeout(()=>{
						uni.switchTab({
							url:'../mine/mine'
						})
					},2000)
					return;
				}
				this.doupdata();
			},
			async doupdata(){
			let data = {};
			data.article_id = this.detail.id;
			data.content = this.desc;
			data.to_user_id = this.detail.author;
			
			let check_access_token = await this.$api.check_access_token();
			console.log(check_access_token);
			if(!check_access_token.data){
				let get_access_token = await this.$api.get_access_token();
			}
			
			let check = await this.$api.msgSecCheck({content:this.desc});
			console.log(check);
			if(check.data.errcode!=0){
				uni.showToast({ title: '请检查评论内容，有敏感词汇', icon: 'none' });
				return;
			}
			let res = await this.$api.newsComment(data) 
			if(res.data.status==0){
				uni.showToast({
					title: '成功',
					duration: 2000
				});
				setTimeout(()=>{
					uni.$emit('refresh');
					uni.navigateBack({
					  delta: 1,  // 返回上一级页面。
					  success: function() {
					      console.log('成功！')
					  }
					})
				},1000)
				
			}
			}
		},
		onLoad(e) {
			console.log(uni.getStorageSync('detail'))
			this.detail = uni.getStorageSync('detail');
		}
	}
</script>

<style>
page {
  background: #fff;
  color: #333;
}
.container{
  padding: 30upx;
  box-sizing: border-box;
}

.tui-cells {
  border-radius: 4upx;
  height: 280upx;
  box-sizing: border-box;
  padding: 20upx 20upx 0 20upx;
  position: relative;
}

.tui-cells::after {
  content: '';
  position: absolute;
  height: 200%;
  width: 200%;
  border: 1px solid #e6e6e6;
  transform-origin: 0 0;
  -webkit-transform-origin: 0 0;
  -webkit-transform: scale(0.5);
  transform: scale(0.5);
  left: 0;
  top: 0;
  border-radius: 8upx;
}

.tui-textarea {
  height: 210upx;
  width: 100%;
  color: #666;
  font-size: 28upx;
}

.tui-phcolor-color {
  color: #ccc !important;
}

.tui-textarea-counter {
  font-size: 24upx;
  color: #999;
  text-align: right;
  height: 40upx;
  line-height: 40upx;
  padding-top: 4upx;
}
.tui-enclosure{
 display: flex;
 align-items: center;
 padding: 26upx 10upx;
 box-sizing: border-box;
}
.tui-mr{
  margin-right: 60upx;
}
.tui-cmt-btn{
  margin-top: 60upx;
}
</style>
